#includeiostream
using namespace std;
#define LL long long
LL n,m,a,b;
LL ret;
int main()
{
    cinnmab;
    if(n1m1) return 0;
    for(int i=0;i=n2;i++)
    {
        if(im) break;
        LL x=ia+min(n-i2,(m-i)2)b;
        ret=max(ret,x);
    }
    coutretendl;
    return 0;
}